package com.example.heathy_me.cardDetail;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.example.heathy_me.MainActivity;
import com.example.heathy_me.R;

public class Edit extends AppCompatActivity {
    private String[] title={"name","date","weight","height","medical","allergy","medicine","blood"};
    private String[] content;
    private EditText name,date,weight,height,medical,allergy,medicine,blood;
    private CheckBox donator;
    private Button confirm;
    private cardDatabaseHelper dbHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);
        name=(EditText)findViewById(R.id.name);
        date=(EditText)findViewById(R.id.date);
        weight=(EditText)findViewById(R.id.weight);
        height=(EditText)findViewById(R.id.height);
        medical=(EditText)findViewById(R.id.medical);
        allergy=(EditText)findViewById(R.id.allergy);
        medicine=(EditText)findViewById(R.id.medicine);
        blood=(EditText)findViewById(R.id.blood);
        confirm=(Button) findViewById(R.id.confirmcard);

        dbHelper=new cardDatabaseHelper(this,"Card.db",null,3);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SQLiteDatabase db=dbHelper.getWritableDatabase();
                ContentValues values=new ContentValues();

                values.put(title[0],name.getText().toString());
                values.put(title[1],date.getText().toString());
                values.put(title[2],weight.getText().toString());
                values.put(title[3],height.getText().toString());
                values.put(title[4],medical.getText().toString());
                values.put(title[5],allergy.getText().toString());
                values.put(title[6],medicine.getText().toString());
                values.put(title[7],blood.getText().toString());

                db.insert("card",null,values);
                Intent intent=new Intent(Edit.this, MainActivity.class);
                intent.putExtra("page",2);
                startActivityForResult(intent,1000);
                //startActivity(intent);
            }
        });
    }
}
